package com.arcpan.Controller;

import com.arcpan.Entity.Query.FileInfoQuery;
import com.arcpan.Entity.Vo.FileInfo;
import com.arcpan.Entity.Vo.ShareInfo;
import com.arcpan.Entity.Vo.ShareInfoVo;
import com.arcpan.Exception.BaseException;
import com.arcpan.Mapper.FileInfoMapper;
import com.arcpan.Mapper.FileShareMapper;
import com.arcpan.Result.Result;
import com.arcpan.Service.FileShareService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/shareInfo")
public class ShareInfoController {
    @Resource
    private FileShareService fileShareService;
    @Resource
    private FileShareMapper fileShareMapper;
    @Resource
    private FileInfoMapper fileInfoMapper;

    @RequestMapping("/info")
    public Result info(String shareId) {
        ShareInfoVo shareInfo = fileShareMapper.getByShareId(shareId);
        return Result.success(shareInfo);
    }

    @RequestMapping("/check")
    public Result check(String shareId, String code) {
        ShareInfo shareInfo = fileShareMapper.getById(shareId, code);
        if (shareInfo == null) {
            throw new BaseException("提取码错误");
        }
        return Result.success(shareInfo);
    }
    @RequestMapping("/sharefile")
    public Result sharefile(String shareId){
        ShareInfoVo shareInfo = fileShareMapper.getByShareId(shareId);
        FileInfoQuery fileInfoQuery=new FileInfoQuery();
        fileInfoQuery.setFileId(shareInfo.getFileId());
        List<FileInfo> list=fileInfoMapper.selectByQuery2(fileInfoQuery);
        return Result.success(list);

    }
}
